<template>
  <div class='content-box'>
    <!-- <div class="box-heard edit">
      <el-button @click="handleAdd()" class="btn_primary" icon="el-icon-plus">
        新增
      </el-button>
    </div> -->
    <div class="box-body" style="height:650px;">
      <el-table :data="riskList" style="width: 100%">
        <el-table-column prop="riskName" label="风险点名称">
        </el-table-column>
        <el-table-column prop="riskDes" label="风险说明">
        </el-table-column>
        <el-table-column prop="riskLevel" label="风险等级">
          <template slot-scope="scope">
            <dict-tag :options="dict.type.risk_level" :value="scope.row.riskLevel" />      
          </template>
        </el-table-column>
        <el-table-column prop="remark" label="备注 ">
        </el-table-column>
        <el-table-column prop="" label="操作" width="100">
          <template slot-scope="scope">
            <div class="button-group">
              <span type="text" class="tag_primary" size="small" @click="handleEdit(scope.row)">查看</span>
              <!-- <span type="text" class="tag_warning" size="small" @click="handleDelete(scope.row)">删除</span> -->
            </div>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div slot="footer" class="dialog-footer" style="display: flex;justify-content: flex-end;align-items: center;width: 100%;">
      <!-- <el-button @click="DialogVisibleUser = false" class="btn_cancel">取 消</el-button>
                    <el-button type="primary" @click="submitFrom('addUserFrom')" class="btn_primary">确 定</el-button> -->
      <!-- <el-button class="btn_cancel" @click="cancel()">取 消</el-button>
      <el-button type="primary" @click="fn()" class="btn_primary">确 定</el-button> -->
    </div>
    <!-- 弹窗 -->
    <RiskPointDialog :riskRowObj="riskRowData" @tempFm="initTableList" v-if="isdialogVisible" :riskdialogVisible="isdialogVisible" @cancelDetail="cancelDetail"></RiskPointDialog>
  </div>
</template>
<script>

import { addProjectPointRisk, updateProjectPointRisk, delProjectPointRisk, getProjectPointRisk, listProjectPointRisk } from "@/api"
import RiskPointDialog from './RiskPointDialog.vue'

export default {
  // 获取父级传递过来的参数
  props: {
    projectPointInfo: {
      type: Object,
      required: true
    }
  },
  dicts: ["risk_level"],
  components: {
    RiskPointDialog,
  },
  data () {
    return {
      // 风险点列表
      riskList: [],
      // 新增编辑弹窗是否显示
      isdialogVisible: false,
      // 行数据
      riskRowData: {},
      formModel: {},
    };
  },
  computed: {},
  watch: {
  },
  methods: {
    // 表格列表
    initTableList () {
      if (this.projectPointInfo.projectPointId) {
        listProjectPointRisk({ projectPointId: this.projectPointInfo.projectPointId }).then(response => {
          this.riskList = response.rows
        })
      } else {
        this.riskList = []
      }
    },
    // 新增用户信息
    handleAdd () {
      this.riskRowData = {}
      this.riskRowData.riskType = 1
      this.riskRowData.projectPointId = this.projectPointInfo.projectPointId
      console.log(this.riskRowData, '新增data')
      this.isdialogVisible = true
    },
    // 修改
    handleEdit (row) {
      this.riskRowData = row
      this.isdialogVisible = true
    },
    // 删除
    handleDelete (row) {
      console.log(row, 'shanchu')
      this.$confirm("确认删除这行数据吗？", "提示", {
        configButtonText: "确定",
        cancelButtonText: "取消",
      })
        .then(() => {
          console.log("点击了确定");
          delProjectPointRisk([row.projectPointRiskId]).then(res => {
            if (res.code == 200) {
              console.log(res, 'res')
              this.$message.success('删除成功')
              this.initTableList()
            }
          })
        })
        .catch(() => {
          console.log("点击了取消");
        });
    },
    // 详情取消
    cancelDetail () {
      this.isdialogVisible = false;
      this.initTableList()
    },
    // 关闭弹窗
    cancel () {
      this.$emit('cancel');
    },
    handleSubmit () {
      this.$emit('cancel')
    }
  },
  created () {
    this.initTableList()
    // setTimeout(() => {
    // console.log(this.projectPointInfo,'projectPsointInfo')
    // }, 300);
  },
  mounted () {

  },
}
</script>

<style lang='less' scoped>
.box-heard.edit {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  margin-bottom: 16px;
}
</style>